/*
 *
 * Copyright (c) 2020 The Raptor Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "raptor-lite/impl/endpoint.h"
#include "src/common/endpoint_impl.h"

namespace raptor {

Endpoint::Endpoint(std::shared_ptr<EndpointImpl> impl)
    : impl_(impl) {}

Endpoint::~Endpoint() {}

uint32_t Endpoint::ConnectionId() { return impl_->ConnectionId(); }
uint64_t Endpoint::SocketFd() { return impl_->SocketFd(); }
uint16_t Endpoint::GetListenPort() { return impl_->GetListenPort(); }
std::string Endpoint::PeerString() { return impl_->PeerString(); }
std::string Endpoint::LocalString() { return impl_->LocalString(); }
void Endpoint::BindContainer(Container *container) { impl_->BindContainer(container); }

bool Endpoint::SendMsg(const Slice &slice) {
    if (slice.empty()) return false;
    return impl_->SendMsg(slice);
}

bool Endpoint::SendMsg(const void *data, size_t len) {
    if (!data || len == 0) return false;
    return impl_->SendMsg(data, len);
}

int Endpoint::SyncSend(const void *data, size_t len) {
    if (!data || len == 0) return 0;
    return impl_->SyncSend(data, len);
}

int Endpoint::SyncRecv(void *data, size_t len) {
    if (!data || len == 0) return 0;
    return impl_->SyncRecv(data, len);
}

void Endpoint::Close(bool notify) { impl_->Close(notify); }
std::string Endpoint::LocalIp() { return impl_->LocalIp(); }
uint16_t Endpoint::LocalPort() { return impl_->LocalPort(); }
std::string Endpoint::RemoteIp() { return impl_->RemoteIp(); }
uint16_t Endpoint::RemotePort() { return impl_->RemotePort(); }
bool Endpoint::IsValid() { return impl_->IsValid(); }
void Endpoint::SetPrivateContext(intptr_t ctx) { impl_->SetPrivateContext(ctx); }
intptr_t Endpoint::PrivateContext() { return impl_->PrivateContext(); }
} // namespace raptor
